export class Subject {
    constructor() {
        this.observers = []
    }
    add(observer) {
        this.observers.push(observer)
    }
    remove(observer) {
        this.observers = this.observers.filter(item => item !== observer)
    }
    notify(data) {
        this.observers.forEach(observer => observer.update(data))
    }
}
export class Observer {
    constructor(name) {
        this.name = name
    }
    update(data) {
        console.log(`${this.name}收到通知，数据为：${data}`)
    }
}
